﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace pistoletyAx
{
    public partial class Form1 : Form
    {
        Controller contr = new Controller();
        public Form1()
        {
            InitializeComponent();
            this.tabControl1.TabPages.Remove(tpSkanowanie);
            this.tabControl1.TabPages.Add(tpLogowanie);
        }

        private void btnLoguj_Click(object sender, EventArgs e)
        {
            bool result = contr.checkPermissions(this.tbLogin.Text, this.tbPasswd.Text);
            if (result)
            {
                this.tabControl1.TabPages.Remove(tpLogowanie);
                this.tabControl1.TabPages.Add(tpSkanowanie);
            }
            else
            {
                MessageBox.Show("Problem z logowaniem!");
            }
        }

        private void cbDokumenty_Click(object sender, EventArgs e)
        {
            this.cbDokumenty.DataSource = contr.GetDokumentList();
        }

        private void cbMagazynierzy_Click(object sender, EventArgs e)
        {
            this.cbMagazynierzy.DataSource = contr.GetMagazynietzyList();
        }

        private void btnOtworzDok_Click(object sender, EventArgs e)
        {
            Kontener kont = contr.GetDocumentPositions(Convert.ToInt32(this.cbDokumenty.Text));
            this.dgvDoZeskanowania.DataSource = kont.tablica1;
            this.dgvZeskanowane.DataSource = kont.tablica2;
        }

        private void tbKodEan_KeyDown(object sender, KeyEventArgs e)
        {
            object obj = contr.GetZeskanowanaPozycja(this.tbKodEan.Text);
            this.dgvZeskanowane.Rows.Add(obj);
        }
    }
}
